#pragma once
#ifndef AUDIOMANAGER_H_
#define AUDIOMANAGER_H_

#include "baseobject.h"
#include "music.h"
#include "sound.h"

void CallbackChannelDone(int nChannel);

namespace EPOC
{
	const unsigned int DEFAULT_FREQUENCY = MIX_DEFAULT_FREQUENCY;
	const Uint16 DEFAULT_FORMAT = MIX_DEFAULT_FORMAT;
	const int DEFAULT_CHANNELS = MIX_DEFAULT_CHANNELS;

	class BaseApplication;
	class AudioManager : public BaseObject
	{
	public:
		AudioManager(BaseApplication *pApplication);
		virtual ~AudioManager();

		virtual void Cleanup();
		virtual bool Initialize(int nMixingChannels = 16, int nFrequency = DEFAULT_FREQUENCY, int nSampleChunkSize = 512, Uint16 nFormat = DEFAULT_FORMAT, int nOutputChannels = DEFAULT_CHANNELS);
		virtual bool Update(float fTimeDelta);

		Music* CreateMusic(std::string sFilePath, int nVolume = 100);

		Sound* CreateSound(std::string sFilePath, int nVolume = 100);
		void DestroySound(Sound *pSound);
		
		void AddSoundObject(Sound *pObject);
		void RemoveSoundObject(Sound *pObject);

		virtual void NotifyChannelDone(int nChannel);

		Mix_Music* LoadMusicFromFile(std::string sFilePath);
		Mix_Music* GetLoadedMusic(std::string sFilePath);
		
		MixChunk* LoadMixChunkFromFile(std::string sFilePath);
		void RemoveLoadedMixChunk(MixChunk *pMixChunk);
		MixChunk* GetLoadedMixChunk(std::string sFilePath);

	protected:
		

	protected:
		bool m_bInitialized;
		int m_nNumTimesOpened;
		int m_nMasterVolume;
		int m_nFrequency;
		int m_nOutputChannels;
		int m_nSampleChunkSize;

		Uint16 m_nFormat;

		int m_nMixingChannels;

		std::list<Music*> m_rMusic;
		std::list<Sound*> m_rSounds;
		
		std::list<MixChunk*> m_rLoadedMixChunks;
		std::map<std::string, Mix_Music*> m_rLoadedMusic;
		//std::map<std::string, Mix_Chunk*> m_rLoadedSound;

		BaseApplication *m_pApplication;
	};

	extern class AudioManager *g_pMixer;
};

#endif